var express = require('express');
var router = express.Router();
const multer = require('multer');
const { SuccessData } = require('../common/returnDataFormat');
const { modifyUser } = require('../controller/adminController');
var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/');
    //文件保存路径
  },
  filename: function (req, file, cb) {
    cb(null, new Date().getTime() + '_' + file.originalname);
    //存储文件名
  },
});
const upload = multer({ storage: storage });
/* GET home page. */
router.get('/', function (req, res, next) {
  res.send('404');
});
router.post('/upload', upload.single('file'), async function (req, res, next) {
  const url = '/' + req.file.path.replace(/\\/g, '/');
  res.send(SuccessData({ path: url }));
});
module.exports = router;
